<?php
/**
 * Created by PhpStorm.
 * User: david
 * Date: 3/22/19
 * Time: 8:31 PM
 */

namespace App\Transformers;


use App\Models\Talent;
use League\Fractal\TransformerAbstract;

class TalentTransfromer extends TransformerAbstract
{
    protected $defaultIncludes = ['first_batch_info', 'second_batch_info', 'hr_batch_info'];

    public function transform(Talent $talent)
    {
        return [
            'id' => $talent->id,
            'name' => $talent->name,
            'recommend' => $talent->recommend,
            'first_recommend' => $talent->first_recommend,
            'sex' => $talent->sex,
            'sex_name' => (int) $talent->sex === 0 ? '男' : '女',
            'birthday' => $talent->birthday,
            'education' => $talent->education,
            'university' => $talent->university,
            'profession' => $talent->profession,
            'interview_status' => $talent->interview_status,
            'interview_status_name' => Talent::INTERVIEW_STATUS_NAME[(int) $talent->interview_status],
            'offer_status' => (int) $talent->offer_status === 1 ? true : false,
            'offer_status_name' => Talent::OFFER_STATUS_NAME[(int) $talent->offer_status],
            'resume' => $talent->resume ? env('APP_URL').'/'.$talent->resume : '',
            'batch' => $talent->batch,
            'batch_id' => $talent->batch_id,
            'first_batch_id' => $talent->first_batch_id,
            'second_batch_id' => $talent->second_batch_id,
            'hr_batch_id' => $talent->hr_batch_id,
            'wait_project_id' => $talent->wait_project_id,
            'wait_status' => $talent->wait_status,
            'wait_status2' => $talent->wait_status2,
            'wait_status3' => $talent->wait_status3,
            'wait_status_name' => Talent::WAIT_STATUS_NAME[(int) $talent->wait_status],
            'wait_status2_name' => Talent::WAIT_STATUS_NAME[(int) $talent->wait_status2],
            'wait_status3_name' => Talent::WAIT_STATUS_NAME[(int) $talent->wait_status3],
            'wait_batch' => $talent->wait_batch,
            'first_recommend_job' => $talent->first_recommend_job,
            'first_status' => $talent->first_status,
            'first_gzdl' => $talent->first_gzdl,
            'first_zyjn' => $talent->first_zyjn,
            'first_xmjy' => $talent->first_xmjy,
            'first_xxcx' => $talent->first_xxcx,
            'first_zxls' => $talent->first_zxls,
            'first_total' => $talent->first_total,
            'first_comment' => $talent->first_comment,
            'first_conclusion' => $talent->first_conclusion,
            'first_interviewer' => $talent->first_interviewer,
            'second_batch' => $talent->second_batch,
            'second_recommend_job' => $talent->second_recommend_job,
            'second_zysy' => $talent->second_zysy,
            'second_zynl' => $talent->second_zynl,
            'second_gzsl' => $talent->second_gzsl,
            'second_gtxz' => $talent->second_gtxz,
            'second_total' => $talent->second_total,
            'second_comment' => $talent->second_comment,
            'second_conclusion' => $talent->second_conclusion,
            'second_interviewer' => $talent->second_interviewer,
            'is_system_in' => $talent->is_system_in,
            'system_in_level' => $talent->system_in_level,
            'recommend_level' => $talent->recommend_level,
            'ability' => $talent->ability,
            'recommend_salary' => (int) $talent->recommend_salary,
            'salary_a' => $talent->salary_a,
            'salary_b' => $talent->salary_b,
            'year' => $talent->year,
            'recently_company' => $talent->recently_company,
            'recently_job' => $talent->recently_job,
            'annual_income' => $talent->annual_income,
            'expected_salary' => $talent->expected_salary,
            'tan_xin_status' => $talent->tan_xin_status,
            'tan_xin' => $talent->tan_xin,
            'tan_xin_a' => $talent->tan_xin_a,
            'tan_xin_b' => $talent->tan_xin_b,
            'tan_xin_reason' => $talent->reason,
            'tijian' => $talent->tijian,
            'tijian_reason' => $talent->tijian_reason,
            'send_offer' => $talent->send_offer,
            'reject_offer_reason' => $talent->reject_offer_reason,
        ];
    }

    public function includeFirstBatchInfo(Talent $talent)
    {
        if (!$talent->first_batch_info) {
            return null;
        }
        return $this->item($talent->first_batch_info, new BatchTransformer());
    }

    public function includeSecondBatchInfo(Talent $talent)
    {
        if (!$talent->second_batch_info) {
            return null;
        }
        return $this->item($talent->second_batch_info, new BatchTransformer());
    }

    public function includeHrBatchInfo(Talent $talent)
    {
        if (!$talent->hr_batch_info) {
            return null;
        }
        return $this->item($talent->hr_batch_info, new BatchTransformer());
    }
}